package com.sneakxy.mybase4j.generator.core;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * 参数
 * @author 潜行的青衣
 * @see
 */
public class Argument {

	private String name;
	
	private ClassType type;
	
	private Annotation annotation;

	public Argument(ClassType type, String name) {
		this.type = type;
		this.name = name;
		if(type == null) {
			throw new NullPointerException("type could not be null.");
		}
		if(StringUtils.isBlank(name)) {
			throw new NullPointerException("name could not be blank.");
		}
	}
	
	public Argument(ClassType type, String name, Annotation annotation) {
		this(type, name);
		this.annotation = annotation;
	}
	
	public List<Type> getImportClassType() {
		List<Type> result = new ArrayList<Type>();
		result.add(type);
		if(this.annotation != null) {
			result.add(annotation);
		}
		return result;
	}
	
	public String toArgumentString() {
		StringBuilder s = new StringBuilder();
		if(this.annotation != null) {
			s.append(this.annotation.toString(true)).append(" ");
		}
		s.append(type.toString(true)).append(" ").append(this.getName());
		return s.toString();
	}
	
	public String getName() {
		return name;
	}

	public ClassType getType() {
		return type;
	}

	public Annotation getAnnotation() {
		return annotation;
	}

	public void setAnnotation(Annotation annotation) {
		this.annotation = annotation;
	}
	
}
